class Configurations < Gtk::Dialog

	def initialize
		super(_('Choose an option'), $main, Gtk::Dialog::MODAL, 
			  [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT],
			  [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT])

		build_window
	end

private

	def build_window
		options = Gtk::Notebook.new
		options.border_width = 6
		
		alignment = Gtk::Alignment.new(0, 0, 0, 0)
		table = Gtk::Table.new(1, 2)
		table.column_spacings = table.row_spacings = 6
		table.border_width = 12

		fg_color = Gtk::ColorButton.new($conf.fg)
		bg_color = Gtk::ColorButton.new($conf.bg)
		font = Gtk::FontButton.new($conf.font)
		width = Gtk::Entry.new
		width.max_length = width.width_chars = 4
		width.text = $conf.text_width.to_s

		table.attach(Gtk::Label.new(_('Font color')).set_xalign(0), 0, 1, 0, 1)
		table.attach(Gtk::Alignment.new(0, 0, 0, 0).add(fg_color), 1, 2, 0, 1)
		table.attach(Gtk::Label.new(_('Background color')).set_xalign(0), 0, 1, 1, 2)
		table.attach(Gtk::Alignment.new(0, 0, 0, 0).add(bg_color), 1, 2, 1, 2)
		table.attach(Gtk::Label.new(_('Text font')).set_xalign(0), 0, 1, 2, 3)
		table.attach(Gtk::Alignment.new(0, 0, 0, 0).add(font), 1, 2, 2, 3)
		table.attach(Gtk::Label.new(_('Editor width (in pixels)')).set_xalign(0), 0, 1, 3, 4)
		table.attach(Gtk::Alignment.new(0, 0, 0, 0).add(width), 1, 2, 3, 4)

		alignment << table
		options.append_page(alignment, Gtk::Label.new(_('Editor')))

		balignment = Gtk::Alignment.new(0, 0, 0, 0)
		btable = Gtk::Table.new(3, 2, false)
		btable.column_spacings = btable.row_spacings = 6
		btable.border_width = 12
		title = Gtk::Entry.new
		title.text = $main.book.title
		subtitle = Gtk::Entry.new
		subtitle.text = $main.book.subtitle
		author = Gtk::Entry.new
		author.text = $main.book.authors[0]
		btable.column_spacings = table.row_spacings = 6
		btable.attach(Gtk::Label.new(_('Title')).set_xalign(0), 0, 1, 0, 1)
		btable.attach(title, 1, 2, 0, 1)
		btable.attach(Gtk::Label.new(_('Subtitle')).set_xalign(0), 0, 1, 1, 2)
		btable.attach(subtitle, 1, 2, 1, 2)
		btable.attach(Gtk::Label.new(_('Author')).set_xalign(0), 0, 1, 2, 3)
		btable.attach(author, 1, 2, 2, 3)
		
		balignment << btable
		options.append_page(balignment, Gtk::Label.new(_('This Book')))

		options.show_all
		self.vbox.pack_start(options)

		self.signal_connect('response') do |w, id|
			if id == Gtk::Dialog::RESPONSE_ACCEPT
				$conf.fg = fg_color.color
				$conf.bg = bg_color.color
				$conf.text_width = width.text.to_i
				$conf.font = font.font_name
				$conf.save

				$main.book.title = title.text
				$main.book.subtitle = subtitle.text
				$main.book.authors = [author.text]
			end
		end
	end

end
